package com.example.controller;

import com.example.common.lang.Result;
import com.example.service.IComicService;
import com.example.vo.ComicInfoVo;
import com.example.vo.ComicVo;
import com.example.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ComicController extends BaseController {

    @GetMapping("/comic/search")
    public String comic(){
        return "/comicDir/comicSearch";
    }

    @PostMapping("/comic/search")
    public String search(String searchStr){

        ArrayList<SearchResultVo> list = comicService.search(searchStr);

        req.setAttribute("pageData", list);

        return "/comicDir/comicList";
    }
    @GetMapping("/comic/comicInfo/{comicId}")
    public String parts(@PathVariable(name = "comicId") String comicId){

        ComicInfoVo vo = comicService.getParts(comicId);

        req.setAttribute("info", vo);

        return "comicDir/comicInfo";

    }
    @GetMapping("/comic/comicInfo/{comicId}/part/{partId}")
    public String part(@PathVariable(name = "comicId") String comicId, @PathVariable(name = "partId") String partId){
        return "comicDir/comic";
    }

    @GetMapping("/comic/comicInfo/{comicId}/part/{partId}.do")
    @ResponseBody
    public ComicVo getPart(@PathVariable(name = "comicId") String comicId, @PathVariable(name = "partId") String partId) throws Exception {

        List<String> list = comicService.getPart(comicId, partId);

        return new ComicVo(comicId, partId, list);
    }


}
